package com.CusterRelSys.control;

import com.CusterRelSys.entity.BasDict;
import com.CusterRelSys.service.DictServiceDy;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by dylx on 2017/12/1.
 */
@Controller
@RequestMapping("/test")
public class DictControllerDy {
@Resource
    private DictServiceDy dictServiceDy;
//    Gson json=new Gson();

    @RequestMapping("/selectAll")
    public String selectAll( ModelMap modelMap){
        List<BasDict> list=dictServiceDy.selectAll();
        System.out.println("pppp");
        modelMap.addAttribute("list",list);
        return "/Views/DictManager";
    }
    @RequestMapping("/selectByNo")
    public String selecyByNo(ModelMap modelMap,Integer dict_id){
        BasDict basDict=dictServiceDy.selectByNo(dict_id);
        System.out.println("wwww");
        modelMap.addAttribute("basdict",basDict);
        return "Views/DictUpdateDy";
    }
    @RequestMapping("/deleteById")
    public String selectById(ModelMap modelMap,Integer dict_id){
        Boolean boo=dictServiceDy.deleteById(dict_id);
        System.out.println("eeee");
        return "/Views/DictManager";
    }
    @RequestMapping("/selectByType")
    public String selectByType(ModelMap modelMap,String dicttype){
        List<BasDict> list1=dictServiceDy.selectByType(dicttype);
        System.out.println("1111");
        modelMap.addAttribute("list1",list1);
        return "/Views/DictManager";
    }
    @RequestMapping("/selectByItem")
    public String selectByItem(ModelMap modelMap,String dictitem){
        List<BasDict> list2=dictServiceDy.selectByItem(dictitem);
        System.out.println("2222");
        modelMap.addAttribute("list2",list2);
        return "/Views/DictManager";
    }
    @RequestMapping("/selectByValue")
    public String selectByValue(ModelMap modelMap,String dictvalue){
        List<BasDict> list3=dictServiceDy.selectByValue(dictvalue);
        System.out.println("3333");
        modelMap.addAttribute("list3",list3);
        return "/Views/DictManager";
    }
    @RequestMapping(value = "/addAll")
    public String addAll(BasDict basDict,String checkstate){
        System.out.println("dydydydy");
        if (checkstate.equals("on")){
            basDict.setDictiseditable(1);
        }else {
            basDict.setDictiseditable(0);
        }

        System.out.println(checkstate);
        System.out.println(basDict);
        int a=dictServiceDy.addAll(basDict);
        System.out.println(a);

/*        modelMap.addAttribute("id",basDict.getDict_id());
        modelMap.addAttribute("type",basDict.getDicttype());
        modelMap.addAttribute("item",basDict.getDictitem());
        modelMap.addAttribute("value",basDict.getDictvalue());
        modelMap.addAttribute("isb",basDict.getDictiseditable());*/

        return "redirect:test/selectAll";
    }
    @RequestMapping("UpdateAll")
    public String UpdateAll(BasDict basDict,ModelMap modelMap){
        dictServiceDy.updateAll(basDict);
        return "redirect:test/selectAll";
    }
}
